package com.eastcom.dataquality.core.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.eastcom.dataquality.core.module.Atom_KpiDefine;

public class KpiDefineDao extends JdbcDaoSupport implements RowMapper<Atom_KpiDefine>{

	public List<Atom_KpiDefine> findKpisById(String dataset_id){
		String sql="select * from QA_KPI_DEFINE where DATASET_ID=?";
		Object[] args=new Object[]{dataset_id};
		int[] types=new int[]{Types.VARCHAR};
		return getJdbcTemplate().query(sql, args, types, this);
	}

	public List<Atom_KpiDefine> findAll(){
		String sql="select * from QA_KPI_DEFINE";
		return getJdbcTemplate().query(sql, this);
	}
	public Atom_KpiDefine mapRow(ResultSet rs, int rowNum) throws SQLException {
		Atom_KpiDefine kpi_define=new Atom_KpiDefine();
		kpi_define.setId(rs.getString("ID"));
		kpi_define.setKpiId(rs.getString("KPI_ID"));
		kpi_define.setCn_name(rs.getString("NAME_CN"));
		kpi_define.setDatasetId(rs.getString("DATASET_ID"));
		kpi_define.setValidationType(rs.getString("VALIDATION_TYPE"));
		kpi_define.setBaselineValue(rs.getDouble("BASELINE_VALUE"));
		kpi_define.setDeviationUp(rs.getDouble("DEVIATION_UP"));
		kpi_define.setDeviationDown(rs.getDouble("DEVIATION_DOWN"));
		kpi_define.setThreadHoldUp(rs.getDouble("THREADHOLD_UP"));
		kpi_define.setThreadHoldDown(rs.getDouble("THREADHOLD_DOWN"));
		kpi_define.setCalendarPolicyUUID(rs.getString("CALENDAR_POLICY_UUID"));
		kpi_define.setColumnName(rs.getString("COLUMN_NAME"));
		return kpi_define;
	}
}
